import java.io.File;

public class Rename{

	public static void main(String[] args) {
		String path = "F:\\documents\\极域多媒体教室互动管理系统软件V2.0\\mh\\Received Files\\班级 62023-12-25-09-04"; // file path
		String suffix = "md"; // the file suffix
		String mark = "_"; // the string need to replace
		String repalceStr = ""; // the string replace mark
		rename(path, suffix, mark, repalceStr);
	}

	/**
	 * batch rename file
	 * @param path directory path
	 * @param suffix file suffix
	 * @param mark the string need to replace
	 * @param repalceStr the string replace mark
	 */
	public static void rename(String path, String suffix, String mark, String repalceStr){
		File file = new File(path);
		if (!file.exists() || !file.isDirectory()) {
			throw new RuntimeException("file path is not exist or is not directory");
		}

		File[] files = file.listFiles((dir, name) -> name.endsWith(suffix));

		for (File f : files) {
			String oldName = f.getName();
			String name = oldName.substring(oldName.indexOf(mark) + 1);
//			String newName = name.replace(mark, repalceStr);
			f.renameTo(new File(path + File.separator + name));
			System.out.println("file " + oldName + " rename to " + name + " success");
		}


	}
	

}